<?php
class acl extends model {
	
	/**
	 * 
	 * @return acl
	 */
	static function getInstance() {
		static $instance;
		if (empty($instance)) {
			$instance = new acl();
		}
		return $instance;
	}
	
	function checkRequest(request $request) {
		$url = $request->module . "/" . $request->action;
		$curacl = $this->loadByField("url", $url);
		if ($curacl === false) {
			message::setDebugMsg("Inserting new URL in ACL table");
			$this->insert(array("url" => $url));
			$curacl = $this->loadByField("url", $url);
		}
		if ((string) $curacl->level === "") {
			message::setDebugMsg("ACL for this page not yet set...");
		} else {
			$reqlevel = (int) $curacl->level;
			$curuser = new user();
			$res = $curuser->loadFromSession();
			if ($res === false) {
				$curlevel = 0;
			} else {
				$curlevel = (int) $curuser->level;
			}
			if ($reqlevel > $curlevel) {
				return false;
			}
		}
		return true;	
	}
	
}
?>